package com.tuzhi.test.sys.web.controller;

import com.alibaba.fastjson2.JSON;
import com.tuzhi.test.sys.service.SysDictionaryService;
import com.tuzhi.util.ObjectTzUtil;
import com.tuzhi.util.StringTzUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
@RequestMapping("/sys/dict")
public class SysDictionaryController {

    @Autowired
    SysDictionaryService sysDictionaryService;

    @GetMapping(value = { "/{dicName}"})
    public String find(@PathVariable(value = "dicName", required = true) String dicName) {
        return sysDictionaryService.find(dicName);

    }

    @GetMapping(value = {"list/{dicName}/{localtion}/{valType}"})
    public String list(@PathVariable(value = "dicName") String dicName,
                       @PathVariable(value = "localtion") String localtion,
                       @PathVariable(value = "valType") String valType) {
        if (StringTzUtil.isNotEmpty(dicName) && StringTzUtil.isNotEmpty(localtion) && StringTzUtil.isNotEmpty(valType)) {
           return JSON.toJSONString(sysDictionaryService.findList(dicName, localtion, ObjectTzUtil.getClassByShortName(valType)));
        }
        return "[]";
    }

    @GetMapping(value = {"map/{dicName}/{valType}"})
    public String map(@PathVariable(value = "dicName") String dicName,
                       @PathVariable(value = "valType") String valType) {
        if (StringTzUtil.isNotEmpty(dicName) && StringTzUtil.isNotEmpty(valType)) {
            return JSON.toJSONString(sysDictionaryService.findMap(dicName, ObjectTzUtil.getClassByShortName(valType)));
        }
        return "{}";
    }





}
